/**
 * @author KujoMiva
 * @name PageFirstScreen.ts
 * @desc 第一页界面
 * @time 2020年03月01日 20:26:58 星期天
 */
class PageFirstScreen extends egret.DisplayObjectContainer {
  public constructor() {
    super()
    this.once(egret.Event.ADDED_TO_STAGE, this.init, this)
  }

  private init() {
    this.createPage()
    this.settingSelf()
    this.showSelf()
  }

  private settingSelf() {
    this.x = -this.width
  }

  private createPage() {
    const page = Utils.createBitmapByName('page_0_all_png')
    this.addChild(page)
    this.addEventListener('hideContent', () => {
      const page_blank = Utils.createBitmapByName('book_bg_png')
      this.addChild(page_blank)
      page_blank.alpha = 0
      egret.Tween.get(page_blank)
        .to({ alpha: 1 }, 200)
        .call(()=>{
          this.dispatchEvent(new egret.Event('pageHideOver'))
        })
    }, this)
  }

  public showSelf() {
    Utils.anchorCenter(this)
    this.y = this.stage.stageHeight / 2
    egret.Tween.get(this)
      .to({ x: this.stage.stageWidth / 2 }, 800)
      .call(() => {
        this.dispatchEvent(new egret.Event('pageShowOver'))
        $('#MivaVideo').show()
      })
  }

  public hideContent() {
    this.dispatchEvent(new egret.Event('hideContent'))
    $('#MivaVideo').remove()
  }
}